<template>
	<view>
		<u-cell-group>
			<u-cell :value="item.deal_text" center v-for="item in highsealist" :key="item.id">
				<view slot="title" class="u-slot-title">
					<text class="u-cell-text">{{item.nickname}}</text>
				</view>
				<view slot="label" class="u-slot-label">
					<view style="color:#909193">客户来源： {{item.scource.name}}</view>
					<u-button type="primary" :customStyle="btnStyle" size="mini" text="详情"
						@click="getBusinessData(item, 'info')"></u-button>
					<u-button type="success" :customStyle="btnStyle" size="mini" text="分配"
						@click="getBusinessData(item, 'allot')"></u-button>
					<u-button type="warning" :customStyle="btnStyle" size="mini" text="领取"
						@click="getBusinessData(item, 'apply')"></u-button>
					<u-button type="error" :customStyle="btnStyle" size="mini" text="删除"
						@click="getBusinessData(item, 'del')"></u-button>
				</view>
			</u-cell>
		</u-cell-group>
		<u-toast ref="uToast"></u-toast>
		<!-- 领取确认框 -->
		<u-modal :show="iSshow" :content='content' showCancelButton @cancel="iSshow = false"
			@confirm="ShowEvent"></u-modal>

		<!-- 删除确认框 -->
		<u-modal :show="Delshow" :content='Delcontent' showCancelButton @cancel="Delshow = false"
			@confirm="delShowEvent"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				btnStyle: {
					width: '10%',
					display: "inline-block",
					marginRight: '5px',
					marginTop: '10px',
					lineHeight: '20px'
				},
				highsealist: [],
				iSshow: false,
				Delshow: false,
				content: '确认是否领取当前客户？',
				Delcontent: '确认是否删除当前客户',
				busid: 0,
				LoginUser: {}
			}
		},
		onReady() {
			this.$u.auth.check();
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {}
			this.getHighseaData()
		},
		methods: {
			async getHighseaData() {
				let result = await this.$u.api.manage.highseaIndex()
				if (result.code == 1) {
					this.highsealist = result.data
				}
			},
			getBusinessData(item, val) {
				switch (val) {
					case 'info':
						uni.navigateTo({
							url: '/pages/manage/highsea/info?busid=' + item.id
						})
						break;
					case 'del':
						this.Delshow = true;
						this.busid = item.id
						this.Delcontent = '确认是否删除' + item.nickname
						break;
					case 'apply':
						this.iSshow = true;
						this.busid = item.id
						this.content = '确认是否领取' + item.nickname
						break;
					case 'allot':
						uni.navigateTo({
							url: '/pages/manage/highsea/allot?busid=' + item.id + '&nickname=' + item.nickname
						})
						break;
				}
			},
			async delShowEvent() {
				this.Delshow = false;
				let result = await this.$u.api.manage.highseaDel({
					id: this.busid
				})
				if (result.code == 1) {
					this.getHighseaData()
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg
					})
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg
					})
				}
			},
			async ShowEvent() {
				this.iSshow = false;
				let result = await this.$u.api.manage.highseaApply({
					busid: this.busid,
					adminid: this.LoginUser.id ,
					status: 'apply'
				})
				if (result.code == 1) {
					this.getHighseaData()
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg
					})
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg
					})
				}
			}
	}
	}
</script>

<style>
</style>